import numpy as np
import Neuron

class Net_Random_Connect:
    def __init__(self,Neuron_Number,Input_Neuron_Num,Output_Neuron_Num):
        Temp = []
        Connection_Number_List = []
        self.Connection_List = []
        self.Weight_List = []
        ID_List = np.array(range(0,Neuron_Number))

        self.Outputs_List = np.zeros(Neuron_Number)

        # for i in range(Neuron_Number):
        #     Connection_Number_List.append(np.random.randint(1,Neuron_Number/5))
        
        Connection_Number_List = np.random.randint(1,Neuron_Number/5,size = Neuron_Number)
        # print (Connection_Number_List)

        for i in Connection_Number_List:
            for j in range(i):
                Temp.append(np.random.choice(ID_List))
            self.Connection_List.append(Temp)
            Temp = []
        # print(Connection_Number_List)
        # print(Connection_List)
        self.Input_Neurons = np.random.randint(0,Neuron_Number,size = Input_Neuron_Num)
        
        self.Output_Neurons = np.random.randint(0,Neuron_Number,size = Output_Neuron_Num)
        # print(self.Output_Neurons)

        # print(self.Input_Neurons)


        for i in Connection_Number_List:
            Temp = np.random.rand(i).tolist()
                # print(Temp)
            self.Weight_List.append(Temp)
            Temp = []
        
        # print(Weight_List)
        self.Bias_List = np.random.rand(Neuron_Number)

        # Create the Neurons
        self.Neurons = [Neuron.Neuron() for i in range(Neuron_Number)]
        
        for i in self.Neurons:
            i.Set_WAB(self.Weight_List[i.ID],self.Bias_List[i.ID])
        
    def Set_Inputs(self,Inputs):
        for i in range(len(self.Input_Neurons)):
            self.Outputs_List[i] = Inputs[i] 

    def Get_Outputs(self):
        Net_Outputs = []
        for i in range(len(self.Output_Neurons)):
            Net_Outputs.append(self.Outputs_List[i])
        return Net_Outputs

    def Step(self):
        Inputs_List = []
        Temp = []
        for i in self.Connection_List:
            for j in i:
                Temp.append(self.Outputs_List[j])
            Inputs_List.append(Temp)
            Temp = []


        for i in self.Neurons:
            self.Outputs_List[i.ID] = i.Step(Inputs_List[i.ID],0.1)
        
        return self.Outputs_List

# Net = Net_Random_Connect(30,3,4)